//
//  DKAuthFaceSecondCell.m
//  DanKU
//
//  Created by 吴斌 on 2023/10/29.
//

#import "DKAuthFaceSecondCell.h"
#import "DKAuthFaceView.h"
static NSString * DKAuthFaceSecondCellId = @"DKAuthFaceSecondCellId";
@interface DKAuthFaceSecondCell()
@property (nonatomic, strong)UILabel * dk_AuthFaceAlertLab;
@property (nonatomic, strong)DKAuthFaceView * dk_AuthFaceView;
@end
@implementation DKAuthFaceSecondCell
+ (instancetype)authFaceSecondCell:(UITableView *)tableView{
    DKAuthFaceSecondCell * dk_AuthFaceSecondCell = [tableView dequeueReusableCellWithIdentifier:DKAuthFaceSecondCellId];
    if (!dk_AuthFaceSecondCell) {
        dk_AuthFaceSecondCell = [[DKAuthFaceSecondCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DKAuthFaceSecondCellId];
    }
    dk_AuthFaceSecondCell.backgroundColor = [UIColor clearColor];
    dk_AuthFaceSecondCell.selectionStyle = UITableViewCellSelectionStyleNone;
    dk_AuthFaceSecondCell.accessoryType = UITableViewCellAccessoryNone;
    return dk_AuthFaceSecondCell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    WeakSelf(self)
    UIView *dk_AuthFaceView = [[UIView alloc] init];
    dk_AuthFaceView.backgroundColor = [UIColor whiteColor];
    dk_AuthFaceView.layer.cornerRadius = DK_IsWidthScale(10);
    dk_AuthFaceView.clipsToBounds = YES;
    [self.contentView addSubview:dk_AuthFaceView];
    [dk_AuthFaceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.top.equalTo(@(DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(315)));
    }];
    self.dk_AuthFaceView = [[DKAuthFaceView alloc] init];
    self.dk_AuthFaceView.layer.cornerRadius = DK_IsWidthScale(95);
    self.dk_AuthFaceView.clipsToBounds = YES;
    [dk_AuthFaceView addSubview:self.dk_AuthFaceView];
    [self.dk_AuthFaceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(@(DK_IsWidthScale(38)));
        make.width.equalTo(@(DK_IsWidthScale(190)));
        make.height.equalTo(@(DK_IsWidthScale(190)));
    }];
    self.dk_AuthFaceView.FaceAuthScuessBlock = ^(DKAuthLiveBase64Model * _Nonnull dk_AuthLiveBase64Mdl) {
        if(weakSelf.FaceAuthScuessBlock){
            weakSelf.FaceAuthScuessBlock(dk_AuthLiveBase64Mdl);
        }
    };
    self.dk_AuthFaceView.FaceAuthFailBlock = ^(NSString * _Nonnull msg) {
        if(weakSelf.FaceAuthFailBlock){
            weakSelf.FaceAuthFailBlock(msg);
        }
    };
    
//    UIImageView * dk_AuthFaceImgView = [[UIImageView alloc] init];
//    dk_AuthFaceImgView.image = DK_GetImage(@"dk_FaceAuthEnticationBg");
//    dk_AuthFaceImgView.userInteractionEnabled = YES;
//    [dk_AuthFaceView addSubview:dk_AuthFaceImgView];
//    [dk_AuthFaceImgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(self);
//        make.top.equalTo(@(DK_IsWidthScale(38)));
//        make.width.equalTo(@(DK_IsWidthScale(190)));
//        make.height.equalTo(@(DK_IsWidthScale(190)));
//    }];
    
    self.dk_AuthFaceAlertLab = [[UILabel alloc] init];
    self.dk_AuthFaceAlertLab.textColor = DK_Hex(@"#333333");
    self.dk_AuthFaceAlertLab.font = DK_FONT_Medium(14);
    self.dk_AuthFaceAlertLab.text = @"Place the face in the frame";
    self.dk_AuthFaceAlertLab.numberOfLines = 0;
    self.dk_AuthFaceAlertLab.textAlignment = NSTextAlignmentCenter;
    [dk_AuthFaceView addSubview:self.dk_AuthFaceAlertLab];
    [self.dk_AuthFaceAlertLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.dk_AuthFaceView.mas_bottom).offset(DK_IsWidthScale(15));
        make.left.equalTo(@(DK_IsWidthScale(68)));
        make.right.equalTo(@(-DK_IsWidthScale(68)));
    }];
    UIView *dk_AuthCertificationBgView = [[UIView alloc] init];
    dk_AuthCertificationBgView.backgroundColor = DK_Hex(@"#4566FF");
    dk_AuthCertificationBgView.layer.cornerRadius = DK_IsWidthScale(25);
    dk_AuthCertificationBgView.clipsToBounds = YES;
    [self.contentView addSubview:dk_AuthCertificationBgView];
    [dk_AuthCertificationBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.top.equalTo(dk_AuthFaceView.mas_bottom).offset(DK_IsWidthScale(52));
        make.height.equalTo(@(DK_IsWidthScale(50)));
    }];
    UIImageView * dk_AuthCertificationImgView = [[UIImageView alloc] init];
    dk_AuthCertificationImgView.image = DK_GetImage(@"dk_AuthCamera");
    dk_AuthCertificationImgView.userInteractionEnabled = YES;
    [dk_AuthCertificationBgView addSubview:dk_AuthCertificationImgView];
    [dk_AuthCertificationImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(dk_AuthCertificationBgView);
        make.left.equalTo(@(DK_IsWidthScale(39)));
        make.width.equalTo(@(DK_IsWidthScale(16)));
        make.height.equalTo(@(DK_IsWidthScale(16)));
    }];
    UILabel * dk_AuthCertificationFaceLab = [[UILabel alloc] init];
    dk_AuthCertificationFaceLab.textColor = DK_Hex(@"#FFFFFF");
    dk_AuthCertificationFaceLab.font = DK_FONT_Semibold(16);
    dk_AuthCertificationFaceLab.text = @"Certification to get the loan";
    [dk_AuthCertificationBgView addSubview:dk_AuthCertificationFaceLab];
    [dk_AuthCertificationFaceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(dk_AuthCertificationImgView.mas_right).offset(DK_IsWidthScale(9));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.bottom.equalTo(@(DK_IsWidthScale(0)));
    }];
    UIButton * dk_AuthFaceCertificationBtn = [[UIButton alloc] init];
    [dk_AuthFaceCertificationBtn addTarget:self action:@selector(authFaceCertification) forControlEvents:UIControlEventTouchUpInside];
    [dk_AuthCertificationBgView addSubview:dk_AuthFaceCertificationBtn];
    [dk_AuthFaceCertificationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@(DK_IsWidthScale(0)));
    }];
    
    UIButton * dk_AgreementBtn = [[UIButton alloc] init];
    [dk_AgreementBtn setTitle:@"《Privacy Agreement》" forState:UIControlStateNormal];
    [dk_AgreementBtn setTitleColor:DK_Hex(@"#CCCCCC") forState:UIControlStateNormal];
    dk_AgreementBtn.titleLabel.font = DK_FONT_Regular(12);
    [dk_AgreementBtn addTarget:self action:@selector(CheckAgreement) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:dk_AgreementBtn];
    [dk_AgreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(dk_AuthCertificationBgView.mas_bottom).offset(DK_IsWidthScale(20));
        make.height.equalTo(@(DK_IsWidthScale(17)));
    }];
}
-(void)setDk_AuthLivenConfigMdl:(DKAuthLivenConfigModel *)dk_AuthLivenConfigMdl{
    _dk_AuthLivenConfigMdl = dk_AuthLivenConfigMdl;
    self.dk_AuthFaceView.dk_AuthLivenConfigMdl = self.dk_AuthLivenConfigMdl;
}
- (void)authFaceCertification{//拍照
    [self.dk_AuthFaceView startCamera];
}
- (void)CheckAgreement{
    if(self.CheckPrivacyAgreementBlock){
        self.CheckPrivacyAgreementBlock();
    }
}
@end
